<?php

namespace api\utils;

class ArrayUtil
{
    public static function isSameArray(array $arr1, array $arr2)
    {
        if (count($arr1) != count($arr2)) {
            return false;
        }

        foreach ($arr1 as $k => $v) {

            if (is_array($v) && is_array($arr2[$k])) {
                if (!self::isSameArray($v, $arr2[$k])) {
                    return false;
                }
            }

            if (!isset($arr2[$k]) || $arr2[$k] != $v) {
                return false;
            }
        }

        return true;
    }

    /**
     * @param array [1,2,3,"3,4,5"]
     * @return array [1,2,3,"3","4","5"]
     */
    public static function explodeInnerArray($array)
    {
        $newArray = [];
        foreach ($array as $value) {
            if (strpos($value, ',')) {
                $newArray = array_merge($newArray, explode(',', $value));
            } else {
                $newArray[] = $value;
            }
        }

        return $newArray;
    }
}
